package reflectPracticeDemo;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
import java.util.TreeMap;

public class reflect_property {

	public static void main(String[] args)
			throws IOException, NoSuchMethodException, SecurityException, InstantiationException,
			IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException {
//回忆property
//本质map，探究map输出形式
//		TreeMap<Integer,String> treemap = new TreeMap<Integer,String>();
//		treemap.put(1, "吴彦祖");
//		System.out.println(treemap);
		
//输出为：{1=吴彦祖}
//可知若想使用property，存储方式为...=...
		Properties pro = new Properties();
		FileReader fr = new FileReader("E:\\java运行文件\\reflectPractice\\Demo");
		pro.load(fr);
		fr.close();

//从PRO读取数据
		String position = pro.getProperty("position");
		
		String method = pro.getProperty("method");

//通过反射来实现student内method1方法
		Class<?> c = Class.forName(position);
//		Class<?> c = Class.forName("reflectPracticeDemo.Student");
		Constructor<?> constructor = c.getConstructor();
		Object obj = constructor.newInstance();

		Method m = c.getMethod(method, String.class);
		m.invoke(obj, "吴彦祖");

	}

}
